// pages/index/xianzhiinfo.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bookimages:[],
    id:0,
    isshoucang:0,
    from:1,
    pingLunContent:'',
      pingLunData:{isShowPingLun:0,value:'',isshuru:0,yifa:0},
      dataInfo:{},
      isShowJieSuan:0,
      liulannum:0,
      orderid:0,
      maiPhone:'',
      isShare:0,
  },
  onShow:function(e){
    var that = this;
    this.setData({
      isshoucang:0
    })
  },
    onShareAppMessage: function (res) {
      console.log(res)
        var id = res.target.dataset.id;
        var path = '/pages/index/xianzhiinfo?isShare=1&id='+id;
        console.log(path);
        return {
            title: '分享',
            path: path
        }
    },
    shouye:function(e){
        wx.reLaunch({
            url: '/pages/find/find'
        })
    },
    onLoad:function(e){
      console.log(e)
      var that = this;
        if(undefined != e.isShare){
            that.setData({
                isShare:e.isShare
            })
        }
      that.setData({
          id:e.id
      })
        this.getDataList();
        this.upliulan();
    },
  addShouCang:function(e){
    var that = this;
    var formdata = {
      otherid:that.data.id,
      from:2
    }
    app.addShouCang(formdata)
    setTimeout(function(){
        that.setData({
          isshoucang:1
        })
        wx.startPullDownRefresh()
    },2000)
  } ,
  onPullDownRefresh: function(){
    wx.stopPullDownRefresh()
  },
  hidePingLun:function(){
    this.setData({
      pingLunData:{isShowPingLun:0}
    })
  },
  showPingLun:function(e){
    this.setData({
      pingLunData:{isShowPingLun:1,yifa:0},
      id:this.data.id,
      from:this.data.from
    })
  },
  gouMai:function(e){
    var that = this;
    var price = that.data.dataInfo.price;
    var freight = that.data.dataInfo.freight;
    var id = that.data.dataInfo.id;
    var uid = that.data.dataInfo.uid;
    //增加交易中判断
    if(null != that.data.orderid && 0 != that.data.orderid){
        wx.showModal({
            title:'提示',
            content:'该商品在交易中'
        })
        return;
    }
    wx.navigateTo({
      url: "/pages/index/order/index?uid="+uid+"&price="+price+"&freight="+freight+"&id="+id
    })

  },

pingluninput:function(e){
    var that = this;
    this.setData({
      pingLunContent:e.detail.value
    })
  },
  fasong:function(e){
      this.setData({
          "pingLunData.yifa":1
      })
      var that = this;
    var formdata = {
      pingLunContent:this.data.pingLunContent,
      uid:getApp().globalData.userInfo.uid,
      otherid:this.data.id,
      from:this.data.from
    }
    // console.log(JSON.stringify(formdata))
    app.pinglun(formdata);
    setTimeout(function(){
        that.hidePingLun();
        that.getDataList();
    },1000)

  },
  showMaiJia:function(e){
      if('' == this.data.maiPhone){
          wx.showModal({
              title:'提示',
              content:'暂无联系方式'
          })
          return ;
      }
      wx.makePhoneCall({
          phoneNumber:this.data.maiPhone
      })
  },
    getDataList:function(e){
        var that = this;
        wx.request({
            url: app.data.server+'/index.php/Tongcheng/Book/getUnuseInfo?id='+that.data.id+'&uid='+getApp().globalData.userInfo.uid+"&longitude="+getApp().globalData.address.longitude+"&latitude="+getApp().globalData.address.latitude,
            success:function(d){
                // console.log('123'+JSON.stringify(d.data));
                // wx.hideLoading();
                // if(0 == d.data){
                //     return;
                // }
                that.setData({
                    dataInfo:d.data,
                    bookimages:d.data.imagearray,
                    isshoucang:d.data.isshoucang,
                    orderid:d.data.order_id,
                    maiPhone:d.data.contract
                })
            }
        })
    },
    //更新浏览量
    upliulan:function(e){
        var that = this;
        wx.request({
            url: app.data.server+'/index.php/Tongcheng/Book/liuLanNum?from=1&id='+that.data.id,
            success:function(d){
                // console.log('123'+JSON.stringify(d.data));
                // wx.hideLoading();
                // if(0 == d.data){
                //     return;
                // }
                that.setData({
                    liulannum:d.data
                })
            }
        })
    },
    bigimg:function(e){
        var url = e.currentTarget.dataset.src;
        // console.log(url)
        wx.previewImage({
            current: url, // 当前显示图片的http链接
            urls: this.data.bookimages // 需要预览的图片http链接列表
        })
    },
    bindblur:function(e){
        var that = this;
        console.log('bindfocus')
        that.setData({
            "pingLunData.isshuru":0
        })
    },
    bindfocus:function(e){
        var that = this;
        console.log('bindfocus')
        that.setData({
            "pingLunData.isshuru":1
        })
    }
})